<!-- Content Header (Page header) -->
<section class="content-header">
 <h1></h1>
</section>
<!-- Main content -->
<section class="content">
 <!-- /.row -->
 <div class="row">
  <div class="col-xs-12">
   <div class="box">
    <div class="box-header">
     <h3 class="box-title"></h3>

     <div class="box-tools">
      <div class="input-group input-group-sm" style="width: 150px;">
       <div class="input-group-btn">
        <button class="btn btn-block btn-primary" onclick="load_page('/pages/blacklist/add.html')">添加IP黑名单</button>
       </div>
        <div class="input-group-btn">
         &nbsp;&nbsp; <button class="btn btn-default" onclick="load_page('/pages/service/list.html');">返回</button>
       </div>
      </div>
     </div>
    </div>
    <div id="server-container" class="box-body table-responsive no-padding">
    </div>
    <!-- /.box-body -->
   </div>
   <!-- /.box -->
  </div>
 </div>
</section>
<script id="server-tpl" type="text/html">
<table class="table table-hover">
  <%for(var i = 0; i < list.length; i++) {%>
  <% if(i==0){%>
  <tr>
   <th>IP</th>
   <th>备注描述</th>
   <th>管理</th>
  </tr>
  <%}%>
  <tr>
   <td><%:=list[i].ip%></td>
   <td><%:=list[i].description%></td>
   <td>
    <a href="javascript:;" data-id="<%:=list[i].id%>" class="ipblacklist-delete">删除</a></td>
  </tr>
  <%}%>
 </table>
</script>
<script type="text/javascript">
    $(".content-header h1").html(domain_name+" > "+service_name+" > IP黑名单管理");
    $(".box-title").html("IP黑名单列表");
    $(function(){
        api_invoke("/api/v1/blacklist/list", {service_id:service_id}, function(data){
            if(data.errno == 0){
                var html = template($("#server-tpl").html(), {list: data.info});
                $("#server-container").html(html);
                $(".ipblacklist-delete").click(function(){
                    var id=$(this).attr("data-id");
                    if(confirm("Please make sure to delete this blacklist?")){
                        delete_blacklist(id);
                    }
                });
            }else{
                alert(data.msg);
            }
        });
    });
    function delete_blacklist(id){
        api_invoke("/api/v1/blacklist/delete", {blacklist_id:id}, function(data){
            if(data.errno == 0){
                load_page("/pages/blacklist/list.html");
            }else{
                alert(data.msg);
            }
        });
    }
</script>
